import java.util.Arrays;
import java.util.PriorityQueue;

public class Test {
    public static int[] findKMax(int[] array,int k){
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        for (int i = 0; i < k; i++) {
            minHeap.offer(array[i]);
        }

        for (int i = k; i < array.length; i++) {
            int top = minHeap.peek();
            if(top < array[i]) {
                minHeap.poll();
                minHeap.offer(array[i]);
            }
        }
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = minHeap.poll();
        }
        return ret;
    }

    public static void main3(String[] args) {
        int[] array = {1,13,41,51,61,71,19};
        int[] ret = findKMax(array,3);
        System.out.println(Arrays.toString(ret));
    }
    public int[] smallestK(int[] arr, int k) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        for(int i = 0;i < arr.length; i++){
            minHeap.offer(arr[i]);
        }
        int[] ret = new int[k];
        for(int i = 0;i < k;i++){
            ret[i] = minHeap.poll();
        }
        return ret;
    }
    public static void main2(String[] args) {
        //默认是一个小根堆
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(1);
        priorityQueue.offer(3);
        priorityQueue.offer(4);
        priorityQueue.offer(7);

        System.out.println(priorityQueue.peek());
    }
    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        testHeap.createHeap();
//        testHeap.offer(80);
//        testHeap.Del(19);

        testHeap.heapSort();
    }
}
